import { _decorator, Component, Node, CCObject, SpriteComponent } from "cc";
const { ccclass, property } = _decorator;

import { UICtrl } from "./../../Managers/UIMgr";
import { EventMgr } from "../../Managers/EventMgr";

@ccclass("ResLoading_Ctrl") // 注意修改类名
export class ResLoading_Ctrl extends UICtrl {

    private progressValue: SpriteComponent = null;
    onLoad() {
        super.onLoad();
        this.progressValue = this.view["UI_progress/value"].getComponent(SpriteComponent);
        this.progressValue.fillRange = 0;

        EventMgr.Instance.add_event_listenner("loadProgress", this, this.onLoaderProgress);
    }

    onLoaderProgress(uname, udata): void {
        udata = (udata > 1) ? 1 : udata;
        udata = (udata < 0) ? 0 : udata;

        this.progressValue.fillRange = udata;
    }

    onDestroy() {
        EventMgr.Instance.remove_event_listenner("loadProgress", this, this.onLoaderProgress);
    }
}
